//
//  AWFilterView.m
//  awu
//
//  Created by centling on 15/8/26.
//  Copyright (c) 2015年 centling. All rights reserved.
//

//[btnRight setTitleEdgeInsets:UIEdgeInsetsMake(0, -imgArrow.size.width, 0, imgArrow.size.width)];
//[btnRight setImageEdgeInsets:UIEdgeInsetsMake(0, btnRight.titleLabel.bounds.size.width, 0, -btnRight.titleLabel.bounds.size.width)];

#import "AWFilterView.h"

BOOL isMoreAgeExtend=NO;
BOOL isMoreBrandExtend=NO;
BOOL isMorePriceExtend=NO;
BOOL isMoreMaterialExtend=NO;

@implementation AWFilterView


//- (instancetype)initWithFrame:(CGRect)frame
//{
//    self = [super initWithFrame:frame];
//    if (self) {
//        self=[[[NSBundle mainBundle] loadNibNamed:@"AWFilterView" owner:self options:nil] firstObject];
//        self.backgroundColor=[UIColor redColor];
//        self.filterView.backgroundColor=[UIColor blueColor];
//        [self addSubview:self.view];
//        
//    }
//    return self;
//}

+ (AWFilterView *)filterView{

    return [[[NSBundle mainBundle] loadNibNamed:@"AWFilterView" owner:self options:nil] firstObject];

}

- (void)awakeFromNib
{
    self.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height * 0.5) ;
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    self.filterView.layer.borderColor=[UIColor lightGrayColor].CGColor;
    self.filterView.layer.borderWidth=0.5f;
    
    UIView *lineView=[[UIView alloc] initWithFrame:CGRectMake(0, 64, [[UIScreen mainScreen] bounds].size.width, 0.5)];
    lineView.backgroundColor=[UIColor lightGrayColor];
    [self.filterView addSubview:lineView];
    
    UIView *lineView2=[[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 0.5)];
    lineView2.backgroundColor=[UIColor lightGrayColor];
    [self.resetOptionsButton addSubview:lineView2];
    
    NSArray *array=@[@"不限",@"新生儿",@"1-3月",@"3-6月",@"6-12月",@"1-2岁",@"2-3岁",@"3-4岁",@"不限",@"新生儿",@"1-3月",@"3-6月",@"3-6月",@"3-6月",@"3-6月",@"3-6月"];
    [self.ageOptionsView addButtonWithViewWidth:[[UIScreen mainScreen] bounds].size.width-(375-284) array:array buttonNumOnLine:4];
    self.ageOptionsView.exclusiveButtonIndex=0;
    if (self.ageOptionsView.rowNum<=2) {
        self.moreAgeButton.hidden=YES;
    }
    
    NSArray *array2=@[@"不限",@"新生儿",@"1-3月",@"3-6月",@"6-12月",@"1-2岁",@"2-3岁",@"3-4岁",@"不限",@"新生儿",@"1-3月",@"3-6月",@"3-6月",@"3-6月",@"3-6月",@"3-6月"];
    [self.brandOptionsView addButtonWithViewWidth:[[UIScreen mainScreen] bounds].size.width-(375-284) array:array2 buttonNumOnLine:4];
    if (self.brandOptionsView.rowNum<=2) {
        self.moreBrandButton.hidden=YES;
    }
    
    NSArray *array3=@[@"不限",@"234",@"456",@"123"];
    [self.priceOptionsView addButtonWithViewWidth:[[UIScreen mainScreen] bounds].size.width-(375-284) array:array3 buttonNumOnLine:4];
    //    [self.priceOptionsView setAllButtonsDisable];
    if (self.priceOptionsView.rowNum<=1) {
        self.morePriceButton.hidden=YES;
    }
    
    NSArray *array4=@[@"不限",@"234",@"456",@"123",@"234",@"456",@"123",@"234"];
    [self.materialOptionsView addButtonWithViewWidth:[[UIScreen mainScreen] bounds].size.width-(375-284) array:array4 buttonNumOnLine:4];
    if (self.materialOptionsView.rowNum<=2) {
        self.moreMaterialButton.hidden=YES;
    }
    
    self.filterScrollView.scrollEnabled=YES;
}


//
- (IBAction)moreAgeButtonClick:(id)sender
{
    if (isMoreAgeExtend) {
        self.ageHeightConstraint.constant=ButtonHeight*2+HorizontalInterverl;
        self.contentViewHeightConstraint.constant-=(self.ageOptionsView.sumHeight-(ButtonHeight*2+HorizontalInterverl));
        isMoreAgeExtend=NO;
        return;
    }
    self.ageHeightConstraint.constant=self.ageOptionsView.sumHeight;
    self.contentViewHeightConstraint.constant+=(self.ageOptionsView.sumHeight-(ButtonHeight*2+HorizontalInterverl));
    isMoreAgeExtend=YES;
}

- (IBAction)moreBrandButtonClick:(id)sender
{
    if (isMoreBrandExtend) {
        self.brandHeightConstraint.constant=ButtonHeight*2+HorizontalInterverl;
        self.contentViewHeightConstraint.constant-=(self.brandOptionsView.sumHeight-(ButtonHeight*2+HorizontalInterverl));
        isMoreBrandExtend=NO;
        return;
    }
    self.brandHeightConstraint.constant=self.brandOptionsView.sumHeight;
    self.contentViewHeightConstraint.constant+=(self.brandOptionsView.sumHeight-(ButtonHeight*2+HorizontalInterverl));
    isMoreBrandExtend=YES;
}


- (IBAction)morePriceButtonClick:(id)sender
{
    if (isMorePriceExtend) {
        self.priceHeightConstraint.constant=ButtonHeight+HorizontalInterverl;
        self.contentViewHeightConstraint.constant-=(self.priceOptionsView.sumHeight-(ButtonHeight*2+HorizontalInterverl));
        isMorePriceExtend=NO;
        return;
    }
    self.priceHeightConstraint.constant=self.priceOptionsView.sumHeight;
    self.contentViewHeightConstraint.constant+=(self.priceOptionsView.sumHeight-(ButtonHeight+HorizontalInterverl));
    isMorePriceExtend=YES;
}


- (IBAction)moreMaterialButtonClick:(id)sender
{
    if (isMoreMaterialExtend) {
        self.materialHeightConstraint.constant=ButtonHeight*2+HorizontalInterverl;
        self.contentViewHeightConstraint.constant-=(self.materialOptionsView.sumHeight-(ButtonHeight*2+HorizontalInterverl));
        isMoreMaterialExtend=NO;
        return;
    }
    self.materialHeightConstraint.constant=self.materialOptionsView.sumHeight;
    self.contentViewHeightConstraint.constant+=(self.materialOptionsView.sumHeight-(ButtonHeight*2+HorizontalInterverl));
    isMoreMaterialExtend=YES;
}


- (IBAction)resetOptionsButtonClick:(id)sender {
    [self.ageOptionsView resetAllButtons];
    [self.brandOptionsView resetAllButtons];
    [self.priceOptionsView resetAllButtons];
    [self.materialOptionsView resetAllButtons];
}

@end
